package club.beimeng.Sender1;



import java.util.ArrayList;
import java.util.Date;

public class Prop { // 获取配置类 首先得获取账号列表.
    int pointNumber = 0;


    ArrayList<Item> emailList = new ArrayList<>(); // 限制每个元素长度是2，第一个是账号，第二个是授权码
    {
        emailList.add(new Item(new String[]{"2877025798@qq.com","ssyyzjurppykdeag"},null));
    }

    public String[] getSender(){ // 账号分享类。要保证每个账号的时间间隔至少3秒
        if (emailList.size() == 0){
            System.out.println(" 可选账号为空 ");
            return null;
        }
        Item item = emailList.get(pointNumber);
        if (item.lastUsingTime != null){
            int mills = (int) ((new Date().getTime() - item.lastUsingTime.getTime()) / 1000);
            if (mills < (3 * 1000)){ // TODO 需要转换成从配置文件取出,应根据数量计算出恰好在三秒内用完所有的
                System.out.println("开始等待");
                try {
                    Thread.sleep((3 * 1000) - mills);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            return item.email;
        }
        item.lastUsingTime = new Date();
        pointNumber += 1;
        pointNumber %= emailList.size();
        return item.email;
    }


    class Item { // 内容承载体类
        String[] email; // 第一位是账号，第二位是密码
        Date lastUsingTime; // 上次使用时间

        public Item(String[] email, Date lastUsingTime) {
            this.email = email;
            this.lastUsingTime = lastUsingTime;
        }

        public String[] getEmail() {
            return email;
        }

        public void setEmail(String[] email) {
            this.email = email;
        }

        public Date getLastUsingTime() {
            return lastUsingTime;
        }

        public void setLastUsingTime(Date lastUsingTime) {
            this.lastUsingTime = lastUsingTime;
        }
    }
}
